import java.util.ArrayList;
import java.util.List;

public class Solution1326 {
    public int minTaps(int n, int[] ranges) {
        List<int[]> list=new ArrayList<>();
        for (int i=0;i<=n;i++){
            list.add(new int[]{Math.max(0,i-ranges[i]),Math.min(n,i+ranges[i])});
        }
        list.sort((a,b)->a[0]==b[0]?b[1]-a[1]:a[0]-b[0]);
        int right=list.get(0)[1],ans=1,max=right;
        for (int i=1;i<list.size();i++){
            if (list.get(i)[0]>max){
                return -1;
            }else if (list.get(i)[0]>right){
                right=max;
                ans++;
            }
            max=Math.max(max,list.get(i)[1]);
        }
        if (n>max){
            return -1;
        }else if (n>right){
            ans++;
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(new Solution1326().minTaps(15,new int[]{1,0,4,0,4,1,4,3,1,1,1,2,1,4,0,3}));
    }
}
